<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>

<script src="layui/layui.js"></script>

<body>
<center>
    <h3>添加用户</h3>

    <form class="layui-form" action="/user/addUser">
        <!--    <div class="layui-form-item">-->
        <!--        <label class="layui-form-label">用户账号</label>-->
        <!--        <div class="layui-input-block">-->
        <!--            <input id="id" type="text" name="id" lay-verify="title" autocomplete="on" class="layui-input">-->
        <!--        </div>-->
        <!--    </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input id="userName" type="text" name="userName" lay-verify="title" autocomplete="on" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input id="userPwd" type="password" name="userPwd" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input id="userRealname" type="text" name="userRealname" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="userGender" value="男" title="男" checked="">
                <input type="radio" name="userGender" value="女" title="女">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input id="userEmail" type="text" name="userEmail" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-block">
                <input id="userPhone" type="text" name="userPhone" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">身份证号</label>
            <div class="layui-input-block">
                <input id="userId" type="text" name="userId" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">出生日期</label>
            <!-- layui-input-block 输入框会占满除文字外的整行 -->
            <div class="layui-input-block">
                <input id="userBirthdate" type="date" name="userBirthdate" lay-verify="date" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否锁定</label>
            <div class="layui-input-block">
                <select name="userLock" id="userLock">
                    <option value="0">解锁</option>
                    <option value="1">锁定</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-block">
                <input id="userAddress" type="text" name="userAddress" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-upload-drag" id="test10">
            <label class="layui-form-label">用户照片</label>
            <i class="layui-icon"></i>
            <p>点击上传，或将文件拖拽到此处</p>
            <div class="layui-hide" id="uploadDemoView">
                <hr>
                <img src="" alt="上传成功后渲染" style="max-width: 196px">
            </div>
        </div>

        <br>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>

</center>
</body>

<script>

    layui.use(['upload', 'element', 'layer'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,element = layui.element
            ,layer = layui.layer;

        //拖拽上传
        upload.render({
            elem: '#test10'
            ,url: 'user/upload'
            ,done: function(res){
                layer.msg('上传成功');
                layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.msg);
                console.log(res)
            }
        });
    });


    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));//把表单中数据转成Json并输出
            //可以写一些验证
            return true;//true表示执行action对应的地址
        });
    });
</script>

</html>